import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;

public class MainWindow extends JFrame {

    static JLabel remainingLabel;
    static JLabel expenseLabel;
    static JLabel daysLeftLabel;
    static JLabel todayExpenseLabel;

    Calendar calendar = Calendar.getInstance();                             // 获取当前日期
    int currentDay = calendar.get(Calendar.DAY_OF_MONTH);                   //今天是这个月的第几天
    int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);    //现在月份的最大天数
    int daysLeft = daysInMonth - currentDay;

    public void Window1(){
        JFrame firstFrame = new JFrame("记账系统");
        firstFrame.setBounds(500,200,100,600);
        firstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //顶层面板和底层面板
        JPanel topPanel = new JPanel(new GridLayout(2, 2));
        JPanel bottomPanel = new JPanel();


        // 创建四个label
        remainingLabel = new JLabel("本月剩余：0");
        remainingLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        daysLeftLabel = new JLabel("距离本月末天数："+daysLeft);
        daysLeftLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        expenseLabel = new JLabel("本月消费：0");
        expenseLabel.setFont(new Font("宋体", Font.PLAIN, 30));
        todayExpenseLabel = new JLabel("今日消费金额：0");
        todayExpenseLabel.setFont(new Font("宋体", Font.PLAIN, 30));


        //按钮“记”
        JButton recordButton = new JButton("记");
        recordButton.setPreferredSize(new Dimension(120, 120));
        String text = recordButton.getText(); // 获取按钮上的文本
        recordButton.setFont(new Font("宋体", Font.PLAIN, 40));
        recordButton.setText(text);

        recordButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Window window = new Window();
                window.setVisible(true);
            }
        });

        firstFrame.setLayout(new BorderLayout());

        // 将组件添加到主窗口
        topPanel.add(remainingLabel);
        topPanel.add(daysLeftLabel);
        topPanel.add(expenseLabel);
        topPanel.add(todayExpenseLabel);
        bottomPanel.add(recordButton);

        // 将顶层面板和底层面板添加到边界布局中
        firstFrame.add(topPanel, BorderLayout.CENTER);
        firstFrame.add(bottomPanel, BorderLayout.SOUTH);

        // 显示主窗口
        firstFrame.pack();
        firstFrame.setSize(700,300);
        firstFrame.setVisible(true);

    }
}
